#
# Makefile for CVE-2019-2215
#
# NDK_ROOT=/home/ashfaq/Android/Sdk/ndk/21.0.6113669 make
#

CXX             := clang++
CXXFLAGS        := -static -O3 -Wall -Wextra

ARCH            := x86_64
NDK_API         ?= 29
CROSS_COMPILE   := $(NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64
TARGET_PLATFORM := $(ARCH)-linux-android

CXX_PATH        := $(CROSS_COMPILE)/bin/$(TARGET_PLATFORM)$(NDK_API)-$(CXX)

TRIGGER_SRC     := trigger.cpp
TRIGGER_OUTPUT  := cve-2019-2215-trigger
EXPLOIT_SRC     := exploit.cpp
EXPLOIT_OUTPUT  := cve-2019-2215-exploit

# default rule
default: all

# phony rules
.PHONY: all

all: clean build-trigger

build-trigger:
	@echo Building: $(TRIGGER_OUTPUT)
	@$(CXX_PATH) $(CXXFLAGS) -o $(TRIGGER_OUTPUT) $(TRIGGER_SRC)

build-exploit:
	@echo Building: $(EXPLOIT_OUTPUT)
	@$(CXX_PATH) $(CXXFLAGS) -o $(EXPLOIT_OUTPUT) $(EXPLOIT_SRC)

clean:
	@echo Removing: $(TRIGGER_OUTPUT)
	@rm -f $(TRIGGER_OUTPUT)
	@echo Removing: $(EXPLOIT_OUTPUT)
	@rm -f $(EXPLOIT_OUTPUT)

push-trigger:
	@echo Pushing: $(TRIGGER_OUTPUT) to /data/local/tmp
	@adb push $(TRIGGER_OUTPUT) /data/local/tmp

push-exploit:
	@echo Pushing: $(EXPLOIT_OUTPUT) to /data/local/tmp
	@adb push $(EXPLOIT_OUTPUT) /data/local/tmp
